Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

202
Visualizações
Plotting additional points on mapquest API map results in "Uncaught TypeError: t.addLayer is not a function"

I am trying to plot locations on a map using the Mapquest API. When the page is loaded, the first script generated the map, and places it in a div, which works properly.

When I call the function "plotPoint()" to add another point on the map, I get the following error: "Uncaught TypeError: t.addLayer is not a function"

<script src="https://api.mqcdn.com/sdk/mapquest-js/v1.3.2/mapquest.js"></script>

<script type="text/javascript">
    L.mapquest.key = 'KEY';
    var map;

      window.onload = function() {

        var map = L.mapquest.map('map', {
          center: [23.1596297, -82.2116596],
          layers: L.mapquest.tileLayer('map'),
          zoom: 8
        });

        L.marker([23.1596297, -82.2116596], {
          icon: L.mapquest.icons.marker(),
          draggable: false
        }).bindPopup('LOCATION 1').addTo(map);

        
      };

function plotPoint(){
        L.marker([23.1796297, -82.2416596], {
          icon: L.mapquest.icons.marker(),
          draggable: false
        }).bindPopup('LOCATION 2').addTo(map);
}
</script>

Any insight or suggestion would be most appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

map was declared as a local variable, when it should have been globally.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda